package task;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;

import org.eclipse.swt.graphics.ImageData;

import util.JdbcUtil;


public class ShowVersion extends DbTask {
	
	static String[] tables = {
			"db_current_version","db_upgrade_history",
	};

	@Override
	public void run(Map<String, String> props) {
		String schema = props.get("schema");
		System.out.printf("NetMaster version of schema '%s':%n", schema);
		for (String table : tables) {
			System.out.printf("Table : %s%n", table);
			String sql = String.format("select * from %s.%s", schema, table);
			try {
				doSql(sql);
			} catch (SQLException e) {
				throw new RuntimeException(e);
			}
		}
	}
	private void doSql(String sql) throws SQLException {
		Statement stmt = conn().createStatement();
		ResultSet rs = stmt.executeQuery(sql);
		JdbcUtil.show(rs);
		rs.close();
		stmt.close();
	}

	@Override
	public String getDescription() {
		String desc = "NetMaster version of a schema";
		return desc;
	}

	@Override
	public ImageData getImageData() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String[] propertyNames() {
		String[] props = { "schema" };
		return props;
	}
}
